import React from 'react';
import Topbar from '../../components/Topbar/Topbar';
import Say from '../../components/Say/Say'
import Bottombar from '../../components/Bottombar/Bottombar'
import axios from 'axios';

class Share extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            data: []
        };
    }

    async componentDidMount() {
        //获取所有动态
        await axios.get('https://www.prebeauty.work/saying')
            .then((res) => {
                this.setState({
                    data: res.data
                })
                console.log(this.state.data)
            })
            .catch((err) => {
                console.log(err);
            })
    }

    goadd() {
        this.props.history.push('/Sharefabu')
    }

    render() {
        return (
            <div className="Share">
                <Topbar name="交流圈" color="#95D2AA" />

                {/* 发布 */}
                <div
                    className="iconfont icon-jia-tianchong"
                    style={{ fontSize: 30, position: 'fixed', bottom: 50, color: '#95D2AA', right: 10, zIndex: 9999 }}
                    onClick={localStorage.getItem('token') ? this.goadd.bind(this) : () => console.log('请先进行登录！')}
                ></div>
                <div style={{minHeight:'580px'}}>
                {
                    this.state.data.map((item, index) => {
                        return (
                            <div key={index}>
                                <Say 
                                    key={index}
                                    time={item.time} 
                                    title={item.title}
                                    content={item.jianjie}
                                    imgsrc={item.imgsrc} 
                                    likenum={item.likenum} 
                                    commentnum={item.commentnum}
                                    sayid={item.sayid}
                                    userid={item.userid}
                                />
                            </div>
                        )
                    })
                }
                </div>

                {/* 页尾 */}
                <Bottombar />
            </div>
        )
    }
}

export default Share